package tongwentongshu.com.app.presenter;

import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
import android.util.Log;

import java.util.Map;

import tongwentongshu.com.app.bean.AppItem;
import tongwentongshu.com.app.bean.PersonalBean;
import tongwentongshu.com.app.contract.CallBackColonyContract;
import tongwentongshu.com.app.contract.PersonalHomePageContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;

/**
 * Created by XiongBin on 2017/7/19.
 */

public class PersonalHomePagePresenter implements PersonalHomePageContract.Presenter {
    PersonalHomePageContract.View personalHomePageView;
    private Map<String, String> map;

    public PersonalHomePagePresenter(PersonalHomePageContract.View personalHomePageView) {
        this.personalHomePageView = personalHomePageView;
    }

    @Override
    public void initMyInfo() {
        map = new ArrayMap<>();
        if (!TextUtils.isEmpty(personalHomePageView.getId()))
            map.put("id", personalHomePageView.getId());
        else
            map.put("mobile", personalHomePageView.getPhone());
        if (!TextUtils.isEmpty(Cache.getToken()))
            map.put("token", Cache.getToken());
        map.put("pagesize", "50");

        UpdateFractory.getBuild()
                .name("PersonalShowCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<PersonalBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(PersonalBean myshare, String msg) {
                        personalHomePageView.onSuccess(myshare);
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });

    }

    @Override
    public void follow(String status) {
        map = new ArrayMap<>();
        map.put("followid", personalHomePageView.getFollowId());
        map.put("token", Cache.getToken());
        map.put("status", status.equals("0") ? "1" : "2");

        UpdateFractory.getBuild()
                .name("AddmyFollowCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<AppItem>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(AppItem poiBean, String msg) {
                        personalHomePageView.onSuccess(poiBean);
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
}
